<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>AnuVadak</title>
        <meta name="generator" content="BBEdit 8.6" />
        <script src="main.js">
        </script>
        <script type="text/javascript" src="http://www.google.com/jsapi">
        </script>
        <script type="text/javascript">
            
            google.load("language", "1");
            
            function initialize(){
                var text = document.getElementById("text").value;
                var tlang = document.getElementById("tlang").value
                google.language.detect(text, function(result){
                    if (!result.error && result.language) {
                        google.language.translate(text, result.language, tlang, function(result){
                            var translated = document.getElementById("translation");
                            if (result.translation) {
                                translated.value = result.translation;
                            }
                        });
                    }
                });
            }
            
            
            function viewResult(error){
                if (error.ErrorCode != 0) {
                    alert("Error in sending message");
                }
                else {
                    alert("Message was send succesfully");
                }
            }
            
            function onSendDone(transId, eventCode, result){
                viewResult(result);
            }
			
			function Message()
			{
				var messageText = document.getElementById("translation").value;
				var urlEncoded = encodeURI(messageText);
				var url = "sms:?body="+urlEncoded;
				window.widget.openURL(url);
				
			}
            
            
            
            function SendSMS(){
            
                var serviceObject = device.getServiceObject("Service.Messaging", "IMessaging");
                var error = 0;
                
                //Criteria object specifies what type of message and message details.
                var criteria = new Object();
                var phoneNumber = document.getElementById("phoneNumber").value;
                //Setting type of the message.
                criteria.MessageType = "SMS";
                if (phoneNumber != null) {
                    //Setting to field of the message, can't be empty
                    criteria.To = phoneNumber;
                }
                else {
                    alert("Phone number is empty");
                    return;
                }
                var messageText = document.getElementById("translation").value;
                if (messageText != null) {
                    //Setting message text field of the message, can't be empty
                    criteria.BodyText = messageText;
                }
                else {
                    alert("Text is empty");
                    return;
                }
                
                try {
                    /*if (document.getElementById("async").checked == false) {
                     //IMessaging::Send, Sending the message syncroniuslly
                     error = serviceObject.IMessaging.Send(criteria);
                     if(error.ErrorCode != 0) {
                     alert( "Error in sending message" );
                     } else {
                     alert("Message was send succesfully");
                     }
                     } else {*/
                    error = serviceObject.IMessaging.Send(criteria);
                    //IMessaging::Send, Sending the message asyncroniuslly.
                    error = serviceObject.IMessaging.Send(criteria, onSendDone);
                    //}
                } 
                catch (exception) {
                    alert("SendSMS error: " + exception);
                }
            }
        </script>
		<link rel="stylesheet" type="text/css" media="screen" href="./css/style.css" />
    </head>
    <body>
        <body>
            <h1 align="center" ><i>AnuVadak</i></h1>
			<label><b>Enter Message here:</b></label>
			<br></br>
			<textarea id="text" name="query" cols = "40" rows = "8"></textarea><br>
			<br></br>
            <select id="tlang" style="width:100px;">
                <option value="sq">Albanian</option>
                <option value="ar">Arabic</option>
                <option value="bg">Bulgarian</option>
                <option value="ca">Catalan</option>
                <option value="zh-TW">Chinese Trad</option>
                <option value="zh-CN">Chinese Simpl</option>
                <option value="hr">Croatian</option>
                <option value="cs">Czech</option>
                <option value="da">Danish</option>
                <option value="nl">Dutch</option>
                <option value="en">English</option>
                <option value="et">Estonian</option>
                <option value="fi">Finnish</option>
                <option value="fr">French</option>
                <option value="gl">Galacian</option>
                <option value="de">German</option>
                <option value="el">Greek</option>
                <option value="iw">Hebrew</option>
                <option value="hi">Hindi</option>
                <option value="hu">Hungarian</option>
                <option value="id">Indonesian</option>
                <option value="it">Italian</option>
                <option value="ja">Japanese</option>
                <option value="ko">Korean</option>
                <option value="lv">Latvian</option>
                <option value="lt">Lithuanian</option>
                <option value="mt">Maltese</option>
                <option value="no">Norwegian</option>
                <option value="pl">Polish</option>
                <option value="pt">Portuguese</option>
                <option value="ro">Romanian</option>
                <option value="ru">Russian</option>
                <option value="sr">Serbian</option>
                <option value="sk">Slovak</option>
                <option value="sl">Slovenian</option>
                <option value="es">Spanish</option>
                <option value="sv">Swedish</option>
                <option value="th">Thai</option>
                <option value="tr">Turkish</option>
                <option value="uk">Ukranian</option>
                <option value="vi">Vietnamese</option>
            </select>
            <input type = "button" value = "Translate" style="width:200px;" onClick ="initialize();">
            <br>
            <br><textarea id="translation" name="results" cols = "40" rows = "8" readonly ="readonly">Your translated message</textarea>
            <br/><br>
            <input type = "button" style="width:200px;" value = "Send Message" onClick ="Message();">
		  </body>
        </html>